﻿<%@ Page Language="C#" AutoEventWireup="false" MasterPageFile="~/SIPO.master" CodeFile="recRegistrationCurrentform.aspx.cs"
    Inherits="SIPO.Web.Forms.Transaction.recRegistrationCurrentform" %>

<asp:Content ID="ctnBody" ContentPlaceHolderID="body" runat="server">
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.min.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.validate.wrapper.js") %>" type="text/javascript"></script>
    <script src="<%= ResolveUrl("~/scripts/jquery.inputmask.bundle.min.js") %>" type="text/javascript"></script>    
    <script type="text/javascript">

        $(document).ready(function () {

            $("#btnNext").button({ icons: { primary: "ui-icon-circle-arrow-e"} });
            $("#btnCancel").button({ icons: { primary: "ui-icon-close"} });
            $("#btnSubmit").button({ icons: { primary: "ui-icon-disk"} });
            $("#btnBack").button({ icons: { primary: "ui-icon-circle-arrow-w"} });

        });

    </script>
    <script type="text/javascript">

        $(document).ready(function () {

            var debtorId = $('#<%= hfDebtorID.ClientID %>').val();

            var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
            if (subsectorname == "") {

            }
            else {
                var sectorid = $('#<%= hfSectorID.ClientID %>').val();
                var sectorcode = $('#<%= hfSectorCode.ClientID %>').val();
                var sectorname = $('#<%= hfSectorName.ClientID %>').val();


                var subsectorid = $('#<%= hfSubSectorID.ClientID %>').val();
                var subsectorcode = $('#<%= hfSubSectorCode.ClientID %>').val();
                var subsectorname = $('#<%= hfSubSectorNames.ClientID %>').val();


                var subsubsectorid = $('#<%= hfSubSubSectorID.ClientID %>').val();
                var subsubsectorcode = $('#<%= hfSubSubSectorCode.ClientID %>').val();
                var subsubsectorname = $('#<%= hfSubSubSectorName.ClientID %>').val();
            }

            $("#fsKonfirmasi").hide();

            $("#btnSubmit").hide();
            $("#btnBack").hide();

            // 1. prepare the validation rules and messages.
            var rules = {
                '<%= ddlRegistrationEmisionType.UniqueID %>': "required"
            };
            var messages = {
                '<%= ddlRegistrationEmisionType.UniqueID %>': "Jenis Registrasi Emisi harus di isi"
            };

            $("#<%= txtNilaiEmisi.ClientID %>").inputmask("decimal", { radixPoint: ",", autoGroup: true, groupSeparator: ".", groupSize: 3, digits: 2, repeat: 18 });

            // 2. Initiate the validator
            var validator = new jQueryValidatorWrapper("frmMasterPage", rules, messages);

            // 3. Set the click event to do the validation
            $("#btnNext").click(function () {

                var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
                var invoicevalue = 0;

                var sectorid = $('#<%= hfSectorID.ClientID %>').val();
                var subsectorid = $('#<%= hfSubSectorID.ClientID %>').val();
                var subsubsectorid = $('#<%= hfSubSubSectorID.ClientID %>').val();

                if ($('#<%= hfInvoiceValue.ClientID %>').val() == 0)
                    invoicevalue = $('#<%= hfValue.ClientID %>').val();
                else
                    invoicevalue = $('#<%= hfInvoiceValue.ClientID %>').val();

                if (sectorid != "" && subsectorid != "" && subsubsectorid != "") {
                    if (parseFloat(invoicevalue) == 0) {
                        Disabled();
                        DisabledJenisEmisi();
                        $('#<%= ddlRegistrationEmisionType.ClientID%>').val('');
                        alert('Jenis Usaha ini belum ada Tarif nya!');
                        return;
                    }
                }

                if (!validator.validate())
                    return;
                else {
                    $("#fsProfilDebitur").hide();
                    $("#fsKonfirmasi").show();
                    $("#btnSubmit").show();
                    $("#btnBack").show();
                    $("#btnNext").hide();
                    ValidasiNPWP();
                    DisplayTarif();

                }
            });

            function DisplayTarif() {
                var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
                var invoicevalue = 0;
                var sector = "";
                var subsector = "";
                var subsubsector = "";
                var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getbespelled.ashx?invoicevalue=") %>';
                if (subsectorname != "") {
                    var sectorcode = $('#<%= hfSectorCode.ClientID %>').val();
                    var sectorname = $('#<%= hfSectorName.ClientID %>').val();
                    sector = sectorcode + '-' + sectorname;
                    sector = sector.split('-');
                    var subsectorcode = $('#<%= hfSubSectorCode.ClientID %>').val();
                    var subsectorname = $('#<%= hfSubSectorNames.ClientID %>').val();
                    subsector = subsectorcode + '-' + subsectorname;
                    subsector = subsector.split('-');
                    var subsubsectorcode = $('#<%= hfSubSubSectorCode.ClientID %>').val();
                    var subsubsectorname = $('#<%= hfSubSubSectorName.ClientID %>').val();
                    subsubsector = subsubsectorcode + '-' + subsubsectorname;
                    subsubsector = subsubsector.split('-');
                }

                var registrasiemisi = $("#<%= ddlRegistrationEmisionType.ClientID%> option:selected").text();
                var registrasiemisiid = $("#<%= ddlRegistrationEmisionType.ClientID%> option:selected").val();
                var jenisemisi = $("#<%= ddlJenisEmisi.ClientID%> option:selected").text();
                var jenisemisiid = $("#<%= ddlJenisEmisi.ClientID%> option:selected").val();

                if ($('#<%= hfInvoiceValue.ClientID %>').val() == 0)
                    invoicevalue = $('#<%= hfValue.ClientID %>').val();
                else
                    invoicevalue = $('#<%= hfInvoiceValue.ClientID%>').val();

                var money = parseFloat(invoicevalue);

                $.ajax({
                    type: 'POST',
                    url: handlerUrl + invoicevalue,
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function (data) {
                        if (data.BeSpelled != "") {
                            if (registrasiemisiid != "") {
                                if (subsector[1].toString().toLowerCase() == 'emiten' || subsector[1].toString().toLowerCase() == 'perusahaan publik') {
                                    if (jenisemisiid != "")
                                        $("#<%= lblValidasi.ClientID%>").html("Biaya " + $('#<%= hfRegistrationLabel.ClientID %>').val() + " " + registrasiemisi + " - " + jenisemisi + " adalah sebesar Rp" + money.formatMoney(2, ".", ",") + " (" + data.BeSpelled + ")" + ". <br/> Surat setoran akan diberikan setelah proses registrasi ini dikonfirmasi");
                                    else
                                        $("#<%= lblValidasi.ClientID%>").html("Biaya " + $('#<%= hfRegistrationLabel.ClientID %>').val() + " " + registrasiemisi + " adalah sebesar Rp" + money.formatMoney(2, ".", ",") + " (" + data.BeSpelled + ")" + ". <br/> Surat setoran akan diberikan setelah proses registrasi ini dikonfirmasi");
                                }
                            }
                            else
                                $("#<%= lblValidasi.ClientID%>").html("Biaya " + $('#<%= hfRegistrationLabel.ClientID %>').val() + " " + subsector[1] + " - " + subsubsector[1] + " adalah sebesar Rp" + money.formatMoney(2, ".", ",") + " (" + data.BeSpelled + ")" + ". <br/> Surat setoran akan diberikan setelah proses registrasi ini dikonfirmasi");
                            $('#<%= hfBeSpelled.ClientID %>').val(data.BeSpelled);
                        }
                        else {
                            if (registrasiemisiid != "") {
                                if (subsector[1].toString().toLowerCase() == 'emiten' || subsector[1].toString().toLowerCase() == 'perusahaan publik') {
                                    if (jenisemisiid != "")
                                        $("#<%= lblValidasi.ClientID%>").html("Biaya " + $('#<%= hfRegistrationLabel.ClientID %>').val() + " " + registrasiemisi + " - " + jenisemisi + " adalah sebesar Rp" + money.formatMoney(2, ".", ",") + " ");
                                    else
                                        $("#<%= lblValidasi.ClientID%>").html("Biaya " + $('#<%= hfRegistrationLabel.ClientID %>').val() + " " + registrasiemisi + " adalah sebesar Rp" + money.formatMoney(2, ".", ",") + " ");
                                }
                            }
                            else
                                $("#<%= lblValidasi.ClientID%>").html("Biaya " + $('#<%= hfRegistrationLabel.ClientID %>').val() + " " + subsector[1] + " - " + subsubsector[1] + " adalah sebesar " + money.formatMoney(2, ".", ",") + " ");
                        }
                    },
                    error: function () {
                        alert('Error!');
                    }
                });
            }

            $("#btnBack").click(function () {

                $("#fsProfilDebitur").show();
                $("#fsKonfirmasi").hide();

                $("#btnSubmit").hide();
                $("#btnBack").hide();
                $("#btnNext").show();
                $("#btnCancel").show();

            });

            function Disabled() {
                $('#<%= txtNilaiEmisi.ClientID%>').attr('disabled', 'disabled');
                $('#<%= txtNilaiEmisi.ClientID%>').val('');
            }
            function DisabledJenisRegistrasi() {
                $('#<%= ddlRegistrationEmisionType.ClientID%>').attr('disabled', 'disabled');
                $ddlRegistrationEmisionTypes = $('#<%= ddlRegistrationEmisionType.ClientID%>');
                $ddlRegistrationEmisionTypes.get(0).options.length = 0;
                $ddlRegistrationEmisionTypes.get(0).options[0] = new Option("-- pilih jenis registrasi emisi --", "");
            }
            function DisabledJenisEmisi() {
                $('#<%= ddlJenisEmisi.ClientID%>').attr('disabled', 'disabled');
                $jenisEmisis = $('#<%= ddlJenisEmisi.ClientID%>');
                $jenisEmisis.get(0).options.length = 0;
                $jenisEmisis.get(0).options[0] = new Option("-- pilih Jenis Penawaran Umum --", "");
            }
            function LoadEmisionType() {
                $jenisEmisis = $('#<%= ddlJenisEmisi.ClientID%>');
                var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getemisiontype.ashx") %>';
                $.ajax({
                    type: 'POST',
                    url: handlerUrl,
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function (datas) {
                        $jenisEmisis.get(0).options.length = 0;
                        $jenisEmisis.get(0).options[0] = new Option("-- pilih Jenis Penawaran Umum --", "");
                        $.each(datas, function (i, data) {
                            $jenisEmisis.append('<option value="' + data.EmisionTypeID + '">' + data.EmisionTypeName + '</option>');
                        });
                    },
                    error: function () {
                        alert('Error!');
                    }
                });
            }
            function Enabled() {
                $('#<%= txtNilaiEmisi.ClientID%>').removeAttr('disabled');
                //$('#ddlJenisEmisi').removeAttr('disabled');
                //LoadEmisionType();
            }
            function EnabledJenisEmisi() {
                $('#<%= ddlJenisEmisi.ClientID%>').removeAttr('disabled');
                LoadEmisionType();
            }
            function EnabledJenisRegistrasi() {
                $('#<%= ddlRegistrationEmisionType.ClientID%>').removeAttr('disabled');
                GetRegistrationEmisionType();
            }
            function ValidasiNPWP() {
                var npwp = "";
                var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
                if (subsectorname != "")
                    npwp = $('#<%= hfNPWP.ClientID %>').val();
                else
                    npwp = $('#txtNPWP').val();

                var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/validasinpwp.ashx?npwp=") %>';
                if (npwp != "") {
                    jQuery.ajax({
                        type: 'POST',
                        url: handlerUrl + npwp,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (datas) {
                            var validasinpwps = '';
                            if (datas.length > 0) {
                                $.each(datas, function (i, data) {
                                    if (data.recSubSector.SubSectorName.toLowerCase() == "emiten" || data.recSector.SectorName.toLowerCase() == "perbankan")
                                        validasinpwps += data.recSubSector.SubSectorName + " \n";
                                    else
                                        validasinpwps += data.recSubSubSector.SubSubSectorName + " \n";
                                    validasinpwps = validasinpwps;
                                });
                                $("#<%= lblTitleValidasiNPWP.ClientID%>").html("NPWP sudah terdaftar sebagai Debitur untuk jenis usaha :");
                                $("#<%= lblValidasiNPWP.ClientID%>").val(validasinpwps);
                            }
                            else {
                                $("#divlblValidasiNPWP").css({ 'display': 'none' });
                                $("#<%= lblTitleValidasiNPWP.ClientID%>").html('');
                                $("#<%= lblValidasiNPWP.ClientID%>").val("");
                            }
                        },
                        error: function () {
                            alert('Error!');
                        }
                    });
                }
                else {
                    $("#divlblValidasiNPWP").css({ 'display': 'none' });
                    $("#<%= lblTitleValidasiNPWP.ClientID%>").html('');
                    $("#<%= lblValidasiNPWP.ClientID%>").val("");
                }
            }


            function GetRegistrationEmisionType() {
                $registrationEmisionTypes = $('#<%= ddlRegistrationEmisionType.ClientID%>');
                var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getregistrationemisiontype.ashx") %>';
                $.ajax({
                    type: 'POST',
                    url: handlerUrl,
                    contentType: 'application/json',
                    dataType: 'json',
                    success: function (datas) {
                        $registrationEmisionTypes.get(0).options.length = 0;
                        $registrationEmisionTypes.get(0).options[0] = new Option("-- pilih jenis registrasi emisi --", "");
                        $.each(datas, function (i, data) {
                            $registrationEmisionTypes.append('<option value="' + data.RegistrationEmisionTypeID + '">' + data.RegistrationEmisionTypeName + '</option>');
                        });
                    },
                    error: function () {
                        alert('Error!');
                    }
                });
            };

            function GetRegistrationEmisionTypeById() {
                var registrationEmisionTypeId = $('#<%= ddlRegistrationEmisionType.ClientID%>').val();
                var handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getregistrationemisiontype.ashx?registrationEmisionTypeId=' + registrationEmisionTypeId + '") %>';
                if (registrationEmisionTypeId != "") {
                    jQuery.ajax({
                        type: 'POST',
                        url: handlerUrl,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (data) {
                            if (data.IsEmision == 1) {
                                EnabledJenisEmisi();
                            }
                            else {
                                DisabledJenisEmisi();
                            }
                        },
                        error: function () {
                            alert('Error!');
                        }
                    });
                }
            }

            function GetTarifBySubSubSectorId() {
                var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
                var subsector = "";
                var subSubSectorId = "";
                if (subsectorname != "") {
                    var subsectorcode = $('#<%= hfSubSectorCode.ClientID %>').val();
                    var subsectorname = $('#<%= hfSubSectorNames.ClientID %>').val();
                    subsector = subsectorcode + '-' + subsectorname;
                    subSubSectorId = $('#<%= hfSubSubSectorID.ClientID %>').val();
                }
                $registrationEmisionTypes = $('#<%= ddlRegistrationEmisionType.ClientID%>');

                var registrationEmisionTypeId = $("#<%= ddlRegistrationEmisionType.ClientID%> option:selected").val();
                var handlerUrl = "";
                if (registrationEmisionTypeId == "")
                    handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/gettarifbysubsubsectorid.ashx?subSubSectorId=' + subSubSectorId + '&transtype=perijinan") %>';
                else
                    handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/gettarifbysubsubsectorid.ashx?subSubSectorId=' + subSubSectorId + '&transtype=perijinan&registrationEmisionTypeId=' + registrationEmisionTypeId + '") %>';
                if (subSubSectorId > 0) {
                    jQuery.ajax({
                        type: 'POST',
                        url: handlerUrl,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (data) {
                            if (data.TariffID != 0) {
                                //alert(data.Value);
                                $('#<%= hfValue.ClientID %>').val(data.Value);
                                $('#<%= hfInvoiceValue.ClientID %>').val(0);
                                $('#<%= hfTarifID.ClientID %>').val(data.TariffID);
                                $('#<%= hfRegistrationLabel.ClientID %>').val(data.RegistrationLabelName);
                                if (data.IsFormula == 1) {
                                    Enabled();
                                    //EnabledJenisEmisi();
                                    $('#<%= hfMinValue.ClientID %>').val(data.MinValue);
                                    $('#<%= hfMaxValue.ClientID %>').val(data.MaxValue);
                                    $('#<%= hfPercentage.ClientID %>').val(data.Percentage);
                                }
                                else {
                                    Disabled();
                                    //DisabledJenisEmisi();
                                    $('#<%= hfMinValue.ClientID %>').val(0);
                                    $('#<%= hfMaxValue.ClientID %>').val(0);
                                    $('#<%= hfPercentage.ClientID %>').val(0);
                                }
                            }
                            else {

                                alert('Jenis Usaha ini belum ada Tarif nya!');
                                GetRegistrationEmisionType();
                                Disabled();
                                DisabledJenisEmisi();
                                if (subsectorname == "") {
                                    $('#<%= ddlRegistrationEmisionType.ClientID%>').attr('disabled', 'disabled');
                                }
                            }
                        },
                        error: function () {
                            alert('Error!');
                        }
                    });
                }
                else {
                    Disabled();
                    DisabledJenisEmisi();
                    if (subsector[1].toString().toLowerCase() == 'emiten') {
                        GetRegistrationEmisionType();
                    }
                    else {
                        $('#<%= ddlRegistrationEmisionType.ClientID%>').removeAttr('disabled');
                    }

                }
            }

            $('#<%= ddlRegistrationEmisionType.ClientID%>').change(function () {
                $('#<%= txtNilaiEmisi.ClientID%>').val('');
                GetTarifBySubSubSectorId();
                GetRegistrationEmisionTypeById();
            });

            $('#<%= txtNilaiEmisi.ClientID%>').blur(function () {

                var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
                var subSubSectorId = "";
                if (subsectorname != "")
                    subSubSectorId = $('#<%= hfSubSubSectorID.ClientID %>').val();
                else
                    subSubSectorId = $("#ddlSubSubSector option:selected").val();

                $registrationEmisionTypes = $('#<%= ddlRegistrationEmisionType.ClientID%>');
                var registrationEmisionTypeId = $("#<%= ddlRegistrationEmisionType.ClientID%> option:selected").val();
                var handlerUrl = "";

                var nilaiEmisi = $('#<%= txtNilaiEmisi.ClientID %>').val();

                if (registrationEmisionTypeId == "")
                    handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getemisionvalue.ashx?subSubSectorId=' + subSubSectorId + '&nilaiemisi=' + nilaiEmisi + '&transtype=perijinan") %>';
                else
                //handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/gettarifbysubsubsectorid.ashx?subSubSectorId=' + subSubSectorId + '&transtype=perijinan&registrationEmisionTypeId=' + registrationEmisionTypeId + '") %>';
                    handlerUrl = '<%= ResolveUrl("~/AjaxHandler/Loaddata/getemisionvalue.ashx?subSubSectorId=' + subSubSectorId + '&nilaiemisi=' + nilaiEmisi + '&transtype=perijinan&registrationEmisionTypeId=' + registrationEmisionTypeId + '") %>';

                if (subSubSectorId > 0 && nilaiEmisi != "") {
                    $.ajax({
                        type: 'POST',
                        url: handlerUrl,
                        contentType: 'application/json',
                        dataType: 'json',
                        success: function (data) {
                            $('#<%= hfValue.ClientID %>').val(data.Value);
                            $('#<%= hfRegistrationLabel.ClientID %>').val(data.RegistrationLabelName);
                            if (data.IsFormula == 1) {
                                //Enabled();
                                $('#<%= hfInvoiceValue.ClientID %>').val(data.InvoiceValue);
                                $('#<%= hfMinValue.ClientID %>').val(data.MinValue);
                                $('#<%= hfMaxValue.ClientID %>').val(data.MaxValue);
                                $('#<%= hfPercentage.ClientID %>').val(data.Percentage);
                            }
                            else {
                                //Disabled();
                                $('#<%= hfMinValue.ClientID %>').val(0);
                                $('#<%= hfMaxValue.ClientID %>').val(0);
                                $('#<%= hfPercentage.ClientID %>').val(0);
                            }
                        },
                        error: function () {
                            alert('Error!');
                        }
                    });
                }
            });

            $("#btnSubmit").click(function () {

                var pilihregistrasi = $("input[name='rbKonfirmasi']:checked").val();
                if (pilihregistrasi == 3) {
                    parent.$('#dialog1').dialog('close');
                }
                else {
                    var userid = $('#txtUserId').val();
                    var password = $('#txtPasswordRegistration').val();
                    var confirmpassword = $('#txtConfirmPassword').val();
                    var debtorname = $('#txtDebtorName').val();
                    var npwp = $('#txtNPWP').val();
                    var jenisemisi = $("#<%= ddlJenisEmisi.ClientID%> option:selected").val();
                    var registrationemisiontypeid = $("#<%= ddlRegistrationEmisionType.ClientID%> option:selected").val();
                    var jenisemisitext = $("#<%= ddlJenisEmisi.ClientID%> option:selected").text();
                    var registrationemisiontypetext = $("#<%= ddlRegistrationEmisionType.ClientID%> option:selected").text();
                    var sectorid = "";
                    var subsectorid = "";
                    var subsubsectorid = "";

                    var sector = "";
                    var subsector = "";
                    var subsubsector = "";
                    var isIndividual = '';
                    var subsectorname = $('#<%= hfSubSectorName.ClientID %>').val();
                    if (subsectorname != "") {
                        sectorid = $('#<%= hfSectorID.ClientID %>').val();
                        var sectorcode = $('#<%= hfSectorCode.ClientID %>').val();
                        var sectorname = $('#<%= hfSectorName.ClientID %>').val();
                        sector = sectorcode + '-' + sectorname;
                        sector = sector.split('-');

                        subsectorid = $('#<%= hfSubSectorID.ClientID %>').val();
                        var subsectorcode = $('#<%= hfSubSectorCode.ClientID %>').val();
                        var subsectorname = $('#<%= hfSubSectorNames.ClientID %>').val();
                        subsector = subsectorcode + '-' + subsectorname;
                        subsector = subsector.split('-');
                        subsubsectorid = $('#<%= hfSubSubSectorID.ClientID %>').val();
                        var subsubsectorcode = $('#<%= hfSubSubSectorCode.ClientID %>').val();
                        var subsubsectorname = $('#<%= hfSubSubSectorName.ClientID %>').val();
                        subsubsector = subsubsectorcode + '-' + subsubsectorname;
                        subsubsector = subsubsector.split('-');
                        isIndividual = false;
                    }
                    else {
                        sectorid = $("#ddlSector option:selected").val();
                        subsectorid = $("#ddlSubSector option:selected").val();
                        subsubsectorid = $("#ddlSubSubSector option:selected").val();

                        sector = $("#ddlSector option:selected").text().split('-');
                        subsector = $("#ddlSubSector option:selected").text().split('-');
                        subsubsector = $("#ddlSubSubSector option:selected").text().split('-');
                    }

                    var nilaiemisi = $('#<%= txtNilaiEmisi.ClientID%>').val();
                    var wilayahid = $("#ddlWilayah option:selected").val();
                    var kotaid = $("#ddlKota option:selected").val();
                    var alamat1 = $('#txtAlamat1').val();
                    var alamat2 = $('#txtAlamat2').val();
                    var alamat3 = $('#txtAlamat3').val();
                    var telpon = $('#txtTelpon').val();
                    var fax = $('#txtFax').val();
                    var email = $('#txtEmail').val();
                    var kodepos = $('#txtKodePos').val();
                    var website = $('#txtWebsite').val();
                    var unformatinvoicevalue = "";
                    if ($('#<%= hfInvoiceValue.ClientID %>').val() == 0) {
                        invoicevalue = parseFloat($('#<%= hfValue.ClientID %>').val());
                        //unformatinvoicevalue = accounting.unformat($('#<%= hfValue.ClientID%>').val(), ",", "."); // Revert to en-US format
                    }
                    else {
                        invoicevalue = parseFloat($('#<%= hfInvoiceValue.ClientID%>').val());
                        //unformatinvoicevalue = accounting.unformat($('#<%= hfInvoiceValue.ClientID%>').val(), ",", "."); // Revert to en-US format
                    }
                    //var invoicevalue = parseFloat(unformatinvoicevalue);
                    var tarifId = $('#<%= hfTarifID.ClientID %>').val();
                    var id = $('#<%= hfID.ClientID %>').val();
                    var isactive = $('#<%= hfIsActive.ClientID %>').val();

                    var bespelled = $('#<%= hfBeSpelled.ClientID %>').val();

                    var registrationlabel = $('#<%= hfRegistrationLabel.ClientID %>').val();

                    var objrecRegistration = new Object();
                    objrecRegistration.RegistrationID = encodeURIComponent(id);
                    objrecRegistration.PreDebtorName = encodeURIComponent(debtorname);
                    objrecRegistration.NPWP = encodeURIComponent(npwp);
                    objrecRegistration.Address1 = encodeURIComponent(alamat1);
                    objrecRegistration.Address2 = encodeURIComponent(alamat2);
                    objrecRegistration.Address3 = encodeURIComponent(alamat3);
                    objrecRegistration.ZipCode = encodeURIComponent(kodepos);
                    objrecRegistration.Email = encodeURIComponent(email);
                    objrecRegistration.Phone = encodeURIComponent(telpon);
                    objrecRegistration.Fax = encodeURIComponent(fax);
                    objrecRegistration.Website = encodeURIComponent(website);
                    objrecRegistration.RegionID = encodeURIComponent(wilayahid);
                    objrecRegistration.CityID = encodeURIComponent(kotaid);
                    objrecRegistration.InvoiceValue = encodeURIComponent(invoicevalue);
                    objrecRegistration.TarifID = encodeURIComponent(tarifId);
                    objrecRegistration.EmisionTypeID = encodeURIComponent(jenisemisi);
                    objrecRegistration.EmisionValue = encodeURIComponent(nilaiemisi);
                    objrecRegistration.SectorID = encodeURIComponent(sectorid);

                    objrecRegistration.SubSectorID = encodeURIComponent(subsectorid);
                    objrecRegistration.SubSubSectorID = encodeURIComponent(subsubsectorid);
                    objrecRegistration.IsActive = encodeURIComponent(isactive);
                    objrecRegistration.IsIndividual = encodeURIComponent(isIndividual);
                    objrecRegistration.BeSpelled = encodeURIComponent(bespelled);
                    objrecRegistration.SectorCode = encodeURIComponent(sector[0]);
                    objrecRegistration.SubSectorCode = encodeURIComponent(subsector[0]);
                    objrecRegistration.SubSectorName = encodeURIComponent(subsector[1]);
                    objrecRegistration.SubSubSectorName = encodeURIComponent(subsubsector[1]);
                    objrecRegistration.RegistrationLabelName = encodeURIComponent(registrationlabel);
                    objrecRegistration.RegistrationEmisionTypeID = encodeURIComponent(registrationemisiontypeid);

                    objrecRegistration.Captcha = encodeURIComponent('internal');
                    objrecRegistration.IsExpired = encodeURIComponent('0');

                    objrecRegistration.RegistrationEmisionTypeText = encodeURIComponent(registrationemisiontypetext);
                    objrecRegistration.EmisionTypeText = encodeURIComponent(jenisemisitext);

                    objrecRegistration.UserCode = encodeURIComponent(userid);
                    objrecRegistration.Password = encodeURIComponent(password);

                    jsonData = JSON.stringify(objrecRegistration);

                    var handlerUrl = '<%= ResolveUrl("~/ajaxhandler/transaction/recRegistrationhandler.ashx") %>';

                    if (id == 0) {
                        $.ajax({
                            type: 'POST',
                            url: handlerUrl + "?method=insert",
                            contentType: 'application/json',
                            dataType: 'json',
                            data: jsonData,
                            success: function (data) {
                                if (data.IsSuccess) {

                                    alert(data.Message);
                                    location.reload();
                                    $('#<%= ddlRegistrationEmisionType.ClientID%>').val('');
                                    $('#<%= ddlJenisEmisi.ClientID%>').val('');
                                    $('#<%= txtNilaiEmisi.ClientID%>').val('');
                                    var formUrl = '<%= ResolveUrl("~/forms/transaction/recPrintInvoiceform.aspx") %>';

                                    window.open(formUrl + '?action=registrasi&invoiceno=' + data.Data + '&email=' + email + '&userid=' + userid + '&password=' + password, '_blank');

                                    parent.$('#dialog1').dialog('close');

                                    setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);
                                }
                                else {

                                    alert(data.Message);

                                }
                            },
                            error: function (response) {
                                var r = JSON.parse(response.responseText);
                                alert("Error Message: " + r.Message);
                            }
                        });

                    }
                    else {
                        CallAjax(handlerUrl, "?method=update", jsonData);
                        parent.$('#dialog1').dialog('close');

                        setTimeout("parent.$('#table').trigger('reloadGrid');", 3000);
                    }

                }
                return false;
            });
        });
    
    </script>
    <script type="text/javascript">

        function ClearText() {
            $('#txtUserId').val('');
        }

        $('#btnCancel').click(function () {

            parent.$('#dialog1').dialog('close');

            return false;
        });
                 
    </script>
    <div>
        <fieldset id="fsProfilDebitur">
            <legend><b>Tambah Penawaran Umum</b></legend>
            <div>
                <table border="0">
                    <tr>
                        <td class="spasiRow">
                            Jenis Registrasi Emisi
                        </td>
                        <td>
                            :
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlRegistrationEmisionType" runat="server" Width="206">
                            </asp:DropDownList>
                        </td>
                        <td class="bintang">
                            *
                        </td>
                    </tr>
                    <tr>
                        <td class="spasiRow">
                            Jenis Penawaran Umum
                        </td>
                        <td>
                            :
                        </td>
                        <td>
                            <asp:DropDownList ID="ddlJenisEmisi" runat="server" Width="206">
                            </asp:DropDownList>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td class="spasiRow">
                            Nilai Emisi (IDR)
                        </td>
                        <td>
                            :
                        </td>
                        <td>
                            <asp:TextBox ID="txtNilaiEmisi" runat="server" Width="200" Style="text-align: right"></asp:TextBox>
                        </td>
                        <td>
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>
        <fieldset id="fsKonfirmasi">
            <legend><b>Konfirmasi</b></legend>
            <div>
                <table border="0">
                    <tr>
                        <td colspan="3">
                            <div id="divlblValidasiNPWP">
                                <asp:Label ID="lblTitleValidasiNPWP" runat="server" ForeColor="#000099" Font-Bold="True"></asp:Label>
                                <br />
                                <asp:TextBox ID="lblValidasiNPWP" runat="server" Font-Size="Small" Wrap="true" Font-Names="Arial"
                                    TextMode="MultiLine" Enabled="false" BorderStyle="None" BackColor="White" Width="750"
                                    ForeColor="#000099"></asp:TextBox>
                            </div>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3">
                            <asp:Label ID="lblValidasi" runat="server" ForeColor="#000099" Width="750px"></asp:Label>
                        </td>
                    </tr>
                    <tr>
                        <td>
                        </td>
                        <td>
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" style="display: none">
                            <input type="radio" title="" name="rbKonfirmasi" value="1" checked="checked" />
                            Registrasi untuk jenis usaha , dengan user id yang sudah anda miliki sebelumnya
                        </td>
                    </tr>
                    <tr>
                        <td colspan="3" style="display: none">
                            <input type="radio" name="rbKonfirmasi" value="2" />
                            Registrasi untuk jenis usaha , dengan user id baru
                        </td>
                    </tr>
                </table>
            </div>
        </fieldset>
        <br />
        <table border="0">
            <tr>
                <td colspan="2">
                </td>
                <td>
                    <div style="text-align: right; padding-top: 10px;">
                        <button id="btnCancel" type="button">
                            Batal</button>
                        <button id="btnBack" type="button">
                            Kembali</button>
                        <button id="btnNext" type="button">
                            Lanjut</button>
                        <button id="btnSubmit" type="button">
                            Submit</button>
                    </div>
                </td>
            </tr>
            <tr>
                <td colspan="2">
                </td>
                <td>
                    <asp:HiddenField ID="hfIsUser" runat="server" />
                    <asp:HiddenField ID="hfDebtorID" runat="server" />
                    <asp:HiddenField ID="hfNPWP" runat="server" />
                    <asp:HiddenField ID="hfSectorID" runat="server" />
                    <asp:HiddenField ID="hfSectorCode" runat="server" />
                    <asp:HiddenField ID="hfSectorName" runat="server" />
                    <asp:HiddenField ID="hfSubSectorID" runat="server" />
                    <asp:HiddenField ID="hfSubSectorCode" runat="server" />
                    <asp:HiddenField ID="hfSubSectorNames" runat="server" />
                    <asp:HiddenField ID="hfSubSubSectorID" runat="server" />
                    <asp:HiddenField ID="hfSubSubSectorCode" runat="server" />
                    <asp:HiddenField ID="hfSubSubSectorName" runat="server" />
                    <asp:HiddenField ID="hfSubSectorName" runat="server" />
                    <asp:HiddenField ID="hfID" runat="server" />
                    <asp:HiddenField ID="hfIsActive" runat="server" />
                    <asp:HiddenField ID="hfInvoiceValue" runat="server" />
                    <asp:HiddenField ID="hfValue" runat="server" />
                    <asp:HiddenField ID="hfMinValue" runat="server" />
                    <asp:HiddenField ID="hfMaxValue" runat="server" />
                    <asp:HiddenField ID="hfPercentage" runat="server" />
                    <asp:HiddenField ID="hfTarifID" runat="server" />
                    <asp:HiddenField ID="hfBeSpelled" runat="server" />
                    <asp:HiddenField ID="hfRegistrationLabel" runat="server" />
                </td>
            </tr>
        </table>
    </div>
</asp:Content>
